import { createStore, applyMiddleware, compose } from 'redux';
// 引入模块化文件
import reducer from './reducer';
import thunk from 'redux-thunk';

// 数据持久化
import { persistStore, persistReducer } from 'redux-persist';
import storageSession from 'redux-persist/lib/storage/session';
const storageConfig = {
    key: 'root', // 必须有的
    storage: storageSession, // 缓存机制
    blacklist: [], // reducer 里不持久化的数据,除此外均为持久化数据
}
const myPersistReducer = persistReducer(storageConfig, reducer);
// 数据持久化

// 这里是使用浏览器插件的配置
const composeFn = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose
const enhancer = composeFn(applyMiddleware(thunk))
// 创建并到处仓库
const store = createStore(myPersistReducer, enhancer);
export const persistor = persistStore(store)   // 数据持久化
export default store;